<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8"%>
<%@taglib uri="/struts-tags" prefix="s"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link
	href="${pageContext.request.contextPath }/admin/assets/css/bootstrap.min.css"
	rel="stylesheet" />
<link rel="stylesheet"
	href="${pageContext.request.contextPath }/admin/css/style.css" />
<link
	href="${pageContext.request.contextPath }/admin/assets/css/codemirror.css"
	rel="stylesheet">
<link rel="stylesheet"
	href="${pageContext.request.contextPath }/admin/assets/css/ace.min.css" />
<link rel="stylesheet"
	href="${pageContext.request.contextPath }/admin/font/css/font-awesome.min.css" />
<script type="text/javascript">
	window.jQuery
			|| document
					.write("<script src='${pageContext.request.contextPath }/admin/assets/js/jquery-2.0.3.min.js'>"
							+ "<"+"/script>");
</script>

<script type="text/javascript">
	if ("ontouchend" in document)
		document
				.write("<script src='${pageContext.request.contextPath }/admin/assets/js/jquery.mobile.custom.min.js'>"
						+ "<"+"/script>");
</script>
<!-- page specific plugin scripts -->
<script type="text/javascript"
	src="${pageContext.request.contextPath }/admin/js/H-ui.js"></script>
<script type="text/javascript"
	src="${pageContext.request.contextPath }/admin/js/H-ui.admin.js"></script>
<script
	src="${pageContext.request.contextPath }/admin/assets/js/bootstrap.min.js"></script>
<script
	src="${pageContext.request.contextPath }/admin/assets/js/typeahead-bs2.min.js"></script>
<script
	src="${pageContext.request.contextPath }/admin/assets/js/jquery.dataTables.min.js"></script>
<script
	src="${pageContext.request.contextPath }/admin/assets/js/jquery.dataTables.bootstrap.js"></script>
<script
	src="${pageContext.request.contextPath }/admin/assets/layer/layer.js"
	type="text/javascript"></script>
<script
	src="${pageContext.request.contextPath }/admin/assets/laydate/laydate.js"
	type="text/javascript"></script>
<style type="text/css">
th {
	text-align: center;
}

td {
	text-align: center;
}
</style>
<title>用户列表</title>
</head>

<body>
	<div class="page-content clearfix">
		<div id="Member_Ratings">
			<div class="d_Confirm_Order_style">
				<div class="border clearfix">
					<span class="l_f"> <a id="batchDe" class="btn btn-danger"><i
							class="fa fa-trash"></i>&nbsp;批量删除</a> <a href="javascript:ovid()"
						class="btn btn-sm btn-primary"><i class="fa fa-check"></i>&nbsp;已浏览</a>
						<a href="javascript:ovid()" class="btn btn-yellow"><i
							class="fa fa-times"></i>&nbsp;未浏览</a>
					</span>
				</div>
				<!---->
				<div class="table_menu_list">
					<table class="table table-striped table-bordered table-hover"
						id="sample-table">
						<thead>
							<tr>
							<tr>
								<th width="25"><label><input type="checkbox"
										class="ace"><span class="lbl"></span></label></th>
								<th>ID</th>
								<th>用户名</th>
								<th>留言内容</th>
								<th>时间</th>
								<th>状态</th>
								<th>是否回复</th>
								<th>操作</th>
							</tr>
						</thead>
						<tbody>
							<s:iterator value="#request.list">
								<tr>
									<td><label><input type="checkbox" class="ace"
											value="${message_id }"><span class="lbl"></span></label></td>
									<td>${message_id }</td>
									<td><u style="cursor: pointer" class="text-primary"
										onclick="member_show('${message_name }','${pageContext.request.contextPath }/selectMessageId','${message_id }','500','320')">${message_name }</u></td>
									<td class="text-l"><a href="javascript:;"
										onclick="Guestbook_iew(${message_id },'${message_name }','${message_text }','${message_time }','${message_state}','${message_answer}','${message_phone}','${message_reply}')">${message_text }</a>
									<td>${message_time }</td>
									<td class="td-status"><span
										class="label label-success radius">${message_state==0?"未游览":"已浏览" }</span></td>
									<td class="td-status"><span
										class="label label-success radius">${message_answer==0?"未回复":"已回复" }</span></td>
									<td class="td-manage"><a
										onclick="Guestbook_iew1(${message_id },'${message_name }','${message_text }','${message_time }','${message_state}','${message_answer}','${message_phone}','${message_reply}')"
										title="回复" href="javascript:;" class="btn btn-xs btn-info"><i
											class="fa fa-edit bigger-120"></i></a> <a href="javascript:;"
										onclick="member_del(this,${message_id })" title="删除"
										class="btn btn-xs btn-warning"><i
											class="fa fa-trash  bigger-120"></i></a></td>
								</tr>
							</s:iterator>
						</tbody>
					</table>
				</div>
			</div>
		</div>
	</div>
	<!--留言详细-->
	<div id="Guestbook" style="display: none">
		<div class="content_style">
			<div class="form-group">
				<label class="col-sm-2 control-label no-padding-right"
					for="form-field-1">留言用户 </label>
				<div class="col-sm-9" id="message_name"></div>
			</div>
			<div class="form-group">
				<label class="col-sm-2 control-label no-padding-right"
					for="form-field-1"> 留言内容 </label>
				<div class="col-sm-9" id="message_text"></div>
			</div>
		</div>
	</div>
	
	<div id="Guestbook1" style="display: none">
		<div class="content_style">
			<div class="col-sm-9">
					<textarea name="权限描述" class="form-control" id="form_textarea"
						placeholder="填写回复内容"></textarea>
					<span class="wordage">剩余字数：<span id="sy"
						style="color: Red;">200</span>字
					</span>
			</div>
		</div>
	</div>
</body>
</html>
<script type="text/javascript">
	jQuery(function($) {
		batchDes();
		var oTable1 = $('#sample-table').dataTable({
			"aaSorting" : [ [ 1, "desc" ] ],//默认第几个排序
			"bStateSave" : true,//状态保存
			"aoColumnDefs" : [
			//{"bVisible": false, "aTargets": [ 3 ]} //控制列的隐藏显示
			{
				"orderable" : false,
				"aTargets" : [ 0, 3, 7 ]
			} // 制定列不参与排序
			]
		});
		$('table th input:checkbox').on(
				'click',
				function() {
					var that = this;
					$(this).closest('table').find(
							'tr > td:first-child input:checkbox').each(
							function() {
								this.checked = that.checked;
								$(this).closest('tr').toggleClass('selected');
							});

				});
		$('[data-rel="tooltip"]').tooltip({
			placement : tooltip_placement
		});
		function tooltip_placement(context, source) {
			var $source = $(source);
			var $parent = $source.closest('table')
			var off1 = $parent.offset();
			var w1 = $parent.width();

			var off2 = $source.offset();
			var w2 = $source.width();

			if (parseInt(off2.left) < parseInt(off1.left) + parseInt(w1 / 2))
				return 'right';
			return 'left';
		}
	});
</script>
<script type="text/javascript">
	/*用户-查看*/
	function member_show(title, url, id, w, h) {
		layer_show(title, url + '?message_id=' + id, w, h);
	}
	/*留言-删除*/
	function member_del(obj, id) {
		layer.confirm('确认要删除吗？', function(index) {
			 $.ajax({
				url:'${pageContext.request.contextPath }/deleteMessage',
				type:"POST",
				data:'message_id='+id,
				dataType:'json',
				success:function(msg){
					if(msg){
						$(obj).parents("tr").remove();
						layer.msg('已删除!', {
							icon : 1,
							time : 1000
						});
					}
				},error:function(){
					layer.msg('删除失败!', {
						icon : 1,
						time : 1000
					});
				}
			}); 
		});
	}
		
	/*字数限制*/
	function checkLength(which) {
		var maxChars = 200; //
		if (which.value.length > maxChars) {
			layer.open({
				icon : 2,
				title : '提示框',
				content : '您输入的字数超过限制!',
			});
			// 超过限制的字数了就将 文本框中的内容按规定的字数 截取
			which.value = which.value.substring(0, maxChars);
			return false;
		} else {
			var curr = maxChars - which.value.length; //250 减去 当前输入的
			document.getElementById("sy").innerHTML = curr.toString();
			return true;
		}
	};
	//批量删除
	var batchDes = function(){
		$('#batchDe').click(function(){
			var checkedObj = [];
			var i=0;
			var checks ="";
			$(":checkbox:checked").each(function(){//获取所有选中的按钮
					if($(this).val()!='on'){
						checks+=$(this).val()+",";
						checkedObj[i++]=this;
					}
			});
			if(checks=="" || checks==null){
				layer.alert('请选择！',{
		            title: '提示框',				
					icon:1,
				});
				return;
			}
			layer.confirm('确认要删除吗？', function(index) {
				 $.ajax({
					url:'${pageContext.request.contextPath }/batcheDeleteMessage',
					type:"POST",
					data:'checks='+checks,
					dataType:'json',
					success:function(msg){
						if(msg){
							for(var i=0;i<checkedObj.length;i++){
								$(checkedObj[i]).parents("tr").remove();
							}
							layer.msg('已删除!', {
								icon : 1,
								time : 1000
							});
							checks="";
							checkedObj.clean();
						}
					},error:function(){
						layer.msg('删除失败!', {
							icon : 1,
							time : 1000
						});
					}
				}); 
			});
			
		});
	}
	laydate({
		elem : '#start',
		event : 'focus'
	});
	
	
	
	/*留言查看*/
	function Guestbook_iew(id,name,text,t,state,answer,phone,r) {
		$("#message_name").text(name);
		$("#message_text").text(text);
		var data = {
				'message_id' : id,
				'message_name' : name,
				'message_text' : text,
				'message_time' : t ,
				'message_phone' : phone ,
				'message_state' : 1,
				'message_answer' : answer,
				'message_reply' : ""
			};
		$.ajax({
			cache: false,
			url:'${pageContext.request.contextPath }/updateMessage',
			type:"POST",
			data: data,
			success:function(msg){
				if(msg){
					var index = layer.open({
						type : 1,
						title : '留言信息',
						maxmin : true,
						shadeClose : false,
						area : [ '600px', '' ],
						content : $('#Guestbook'),
						btn : [ '确定' ],
						yes : function(index, layero) {
							location.reload();//刷新页面
						}
					})
				}
			},error:function(){
				alert("信息获取失败！");
			}
		}); 
	};
	
	/*留言查看*/
	function Guestbook_iew1(id,name,text,t,state,answer,phone,r) {
		$("#form_textarea").val(r);
		var index = layer.open({
			type : 1,
			title : '留言信息',
			maxmin : true,
			shadeClose : false,
			area : [ '600px', '' ],
			content : $('#Guestbook1'),
			btn : [ '确定', '取消' ],
			yes : function(index, layero) {
				if ($('.form-control').val() == "") {
					layer.alert('回复内容不能为空！', {
						title : '提示框',
						icon : 0,
					})
				}else {
					layer.alert('确定回复该内容？', {
						title : '提示框',
						icon : 0,
						btn : [ '确定', '取消' ],
						yes : function(index) {
							layer.alert('回复成功！',{
					            title: '提示框',				
								icon:1,
								end: function () {
									var te = $("#form_textarea").val();
									$.ajax({
										url:'${pageContext.request.contextPath }/updateMessage',
										type:"POST",
										data: {
											'message_id' : id,
											'message_name' : name,
											'message_text' : text,
											'message_time' : t ,
											'message_phone' : phone ,
											'message_state' : state,
											'message_answer' : 1,
											'message_reply' : te
										},
										success:function(msg){
											if(msg){
												location.reload();//刷新页面
											}
										}
									});
					            }
							});
						}
					});
				}
			}
		})
	};
</script>